(function (vc) {

    vc.extends({
        data: {
            addAMenuInfo: {
                hktId: '',
                hktName: '',
                hktIcon: '',
                hktDesc: '',
                label: '',
                seq: '',
                url: '',
                skipType: '2',
                isShow: '',
                typeCd: '2002',
            },
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('addAMenu', 'openAddAMenuModal', function (_param) {
                vc.copyObject(_param, $that.addAMenuInfo);
                $('#addAMenuModel').modal('show');
            });
            vc.on("addAMenu", "notifyUploadCoverImage", function (_param) {
                if (_param) {
                    $that.addAMenuInfo.hktIcon = _param[0]
                } else {
                    $that.addAMenuInfo.hktIcon = '';
                }
            });
        },
        methods: {
            addAMenuValidate() {
                return vc.validate.validate({
                    addAMenuInfo: $that.addAMenuInfo
                }, {
                    'addAMenuInfo.hktName': [{
                        limit: "required",
                        param: "",
                        errInfo: "类别名称不能为空"
                    },
                    {
                        limit: "maxLength",
                        param: "30",
                        errInfo: "类别名称名称太长"
                    },
                    ],
                    'addAMenuInfo.hktIcon': [{
                        limit: "required",
                        param: "",
                        errInfo: "小图标不能为空"
                    }],
                    'addAMenuInfo.hktDesc': [{
                        limit: "maxLength",
                        param: "50",
                        errInfo: "服务描述太长"
                    },],
                    'addAMenuInfo.label': [{
                        limit: "maxLength",
                        param: "15",
                        errInfo: "标签描述太长"
                    },],
                    'addAMenuInfo.seq': [{
                        limit: "required",
                        param: "",
                        errInfo: "排序不能为空"
                    },
                    {
                        limit: "num",
                        param: "",
                        errInfo: "排序不是有效数字"
                    },
                    ],
                    'addAMenuInfo.isShow': [{
                        limit: "required",
                        param: "",
                        errInfo: "是否显示不能为空"
                    },
                    {
                        limit: "maxLength",
                        param: "2",
                        errInfo: "是否显示格式错误"
                    },
                    ],
                    'addAMenuInfo.typeCd': [{
                        limit: "required",
                        param: "",
                        errInfo: "请选择类型"
                    }]
                });
            },
            saveHousekeepingTypeInfo: function () {
                if (!$that.addAMenuValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.http.apiPost(
                    '/productMenu.saveProductMenu',
                    JSON.stringify($that.addAMenuInfo), {
                    emulateJSON: true
                },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addAMenuModel').modal('hide');
                            $that.clearAddAMenuInfo();
                            vc.emit('housekeepingType', 'listHousekeepingType', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);

                    });
            },

            clearAddAMenuInfo: function () {
                $that.addAMenuInfo = {
                    hktId: '',
                    hktName: '',
                    hktIcon: '',
                    hktDesc: '',
                    label: '',
                    seq: '',
                    url: '',
                    skipType: '2',
                    isShow: '',
                    typeCd: '2002',
                };
                vc.emit("addAMenu", 'uploadImage', 'clearImage', {})
            }
        }
    });

})(window.vc);